﻿using Microsoft.Win32;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using RDWSMTool.Model;
using SXJ;
using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows;

namespace RDWSMTool.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        #region 变量
        Mysql mysql = new Mysql();
        bool actionFinsh = false;
        #endregion
        #region 属性绑定
        private string _title = "RDWSMTool";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }
        private string version = "1.10";
        public string Version
        {
            get { return version; }
            set { SetProperty(ref version, value); }
        }
        private bool sQLState = false;
        public bool SQLState
        {
            get { return sQLState; }
            set { SetProperty(ref sQLState, value); }
        }
        private string dileveryorderCN = "";
        public string DileveryorderCN
        {
            get { return dileveryorderCN; }
            set { SetProperty(ref dileveryorderCN, value); }
        }
        private string dileveryorderRemark = "";
        public string DileveryorderRemark
        {
            get { return dileveryorderRemark; }
            set { SetProperty(ref dileveryorderRemark, value); }
        }
        private DateTime dileveryOrderCheckStartDate = DateTime.Now;
        public DateTime DileveryOrderCheckStartDate
        {
            get { return dileveryOrderCheckStartDate; }
            set { SetProperty(ref dileveryOrderCheckStartDate, value); }
        }
        private DateTime dileveryrderCheckEndDate = DateTime.Now;
        public DateTime DileveryrderCheckEndDate
        {
            get { return dileveryrderCheckEndDate; }
            set { SetProperty(ref dileveryrderCheckEndDate, value); }
        }
        private ObservableCollection<Dileveryorder> dileveryOrderCheck = new ObservableCollection<Dileveryorder>();
        public ObservableCollection<Dileveryorder> DileveryOrderCheck
        {
            get { return dileveryOrderCheck; }
            set { SetProperty(ref dileveryOrderCheck, value); }
        }
        private string goodsOriginalCN = "";
        public string GoodsOriginalCN
        {
            get { return goodsOriginalCN; }
            set { SetProperty(ref goodsOriginalCN, value); }
        }
        private string goodsName = "";
        public string GoodsName
        {
            get { return goodsName; }
            set { SetProperty(ref goodsName, value); }
        }
        private string goodsModel = "";
        public string GoodsModel
        {
            get { return goodsModel; }
            set { SetProperty(ref goodsModel, value); }
        }
        private string goodsPosition = "";
        public string GoodsPosition
        {
            get { return goodsPosition; }
            set { SetProperty(ref goodsPosition, value); }
        }
        private ObservableCollection<Goods> goodsCheck = new ObservableCollection<Goods>();
        public ObservableCollection<Goods> GoodsCheck
        {
            get { return goodsCheck; }
            set { SetProperty(ref goodsCheck, value); }
        }
        private Goods goodsCheckSelectedItem;
        public Goods GoodsCheckSelectedItem
        {
            get { return goodsCheckSelectedItem; }
            set { SetProperty(ref goodsCheckSelectedItem, value); }
        }
        private string inputOrderOriginalDCN = "";
        public string InputOrderOriginalDCN
        {
            get { return inputOrderOriginalDCN; }
            set { SetProperty(ref inputOrderOriginalDCN, value); }
        }

        private ObservableCollection<InputGoods> inputOrderCheck = new ObservableCollection<InputGoods>();
        public ObservableCollection<InputGoods> InputOrderCheck
        {
            get { return inputOrderCheck; }
            set { SetProperty(ref inputOrderCheck, value); }
        }
        private string outputOrderRecordCN = "";
        public string OutputOrderRecordCN
        {
            get { return outputOrderRecordCN; }
            set { SetProperty(ref outputOrderRecordCN, value); }
        }
        private string outputOrderRecordPerson = "";
        public string OutputOrderRecordPerson
        {
            get { return outputOrderRecordPerson; }
            set { SetProperty(ref outputOrderRecordPerson, value); }
        }
        private string outputOrderRecordRemark = "";
        public string OutputOrderRecordRemark
        {
            get { return outputOrderRecordRemark; }
            set { SetProperty(ref outputOrderRecordRemark, value); }
        }
        private DateTime outputOrderRecordCheckStartDate = DateTime.Now;
        public DateTime OutputOrderRecordCheckStartDate
        {
            get { return outputOrderRecordCheckStartDate; }
            set { SetProperty(ref outputOrderRecordCheckStartDate, value); }
        }
        private DateTime outputOrderRecordCheckEndDate = DateTime.Now;
        public DateTime OutputOrderRecordCheckEndDate
        {
            get { return outputOrderRecordCheckEndDate; }
            set { SetProperty(ref outputOrderRecordCheckEndDate, value); }
        }
        private ObservableCollection<OutputRecord> outputOrderRecordCheck = new ObservableCollection<OutputRecord>();
        public ObservableCollection<OutputRecord> OutputOrderRecordCheck
        {
            get { return outputOrderRecordCheck; }
            set { SetProperty(ref outputOrderRecordCheck, value); }
        }
        private OutputRecord outputOrderRecordSelectedItem;
        public OutputRecord OutputOrderRecordSelectedItem
        {
            get { return outputOrderRecordSelectedItem; }
            set { SetProperty(ref outputOrderRecordSelectedItem, value); }
        }
        private string outputOrderCN = "";
        public string OutputOrderCN
        {
            get { return outputOrderCN; }
            set { SetProperty(ref outputOrderCN, value); }
        }
        private ObservableCollection<OutputGoods> outputOrderCheck = new ObservableCollection<OutputGoods>();
        public ObservableCollection<OutputGoods> OutputOrderCheck
        {
            get { return outputOrderCheck; }
            set { SetProperty(ref outputOrderCheck, value); }
        }
        private string deliveryOrderPageVisibility = "Visible";
        public string DeliveryOrderPageVisibility
        {
            get { return deliveryOrderPageVisibility; }
            set { SetProperty(ref deliveryOrderPageVisibility, value); }
        }
        private string goodsPageVisibility = "Collapsed";
        public string GoodsPageVisibility
        {
            get { return goodsPageVisibility; }
            set { SetProperty(ref goodsPageVisibility, value); }
        }
        private string inputOrderPageVisibility = "Collapsed";
        public string InputOrderPageVisibility
        {
            get { return inputOrderPageVisibility; }
            set { SetProperty(ref inputOrderPageVisibility, value); }
        }
        private string outputRecordPageVisibility = "Collapsed";
        public string OutputRecordPageVisibility
        {
            get { return outputRecordPageVisibility; }
            set { SetProperty(ref outputRecordPageVisibility, value); }
        }
        private string outputOrderPageVisibility = "Collapsed";
        public string OutputOrderPageVisibility
        {
            get { return outputOrderPageVisibility; }
            set { SetProperty(ref outputOrderPageVisibility, value); }
        }
        private bool isGoodsCountGreaterthanZero = false;
        public bool IsGoodsCountGreaterthanZero
        {
            get { return isGoodsCountGreaterthanZero; }
            set { SetProperty(ref isGoodsCountGreaterthanZero, value); }
        }
        #endregion
        #region 方法绑定
        private DelegateCommand<object> dileveryOrderCommand;        
        public DelegateCommand<object> DileveryOrderCommand =>
            dileveryOrderCommand ?? (dileveryOrderCommand = new DelegateCommand<object>(ExecuteDileveryOrderCommand));
        private DelegateCommand<object> menuCommand;
        public DelegateCommand<object> MenuCommand =>
            menuCommand ?? (menuCommand = new DelegateCommand<object>(ExecuteMenuCommand));
        private DelegateCommand<object> goodsCommand;
        public DelegateCommand<object> GoodsCommand =>
            goodsCommand ?? (goodsCommand = new DelegateCommand<object>(ExecuteGoodsCommand));
        private DelegateCommand<object> inputOrderCommand;
        public DelegateCommand<object> InputOrderCommand =>
            inputOrderCommand ?? (inputOrderCommand = new DelegateCommand<object>(ExecuteInputOrderCommand));
        private DelegateCommand<object> outputOrderRecordCommand;
        public DelegateCommand<object> OutputOrderRecordCommand =>
            outputOrderRecordCommand ?? (outputOrderRecordCommand = new DelegateCommand<object>(ExecuteOutputOrderRecordCommand));
        private DelegateCommand appLoadedEventCommand;
        public DelegateCommand AppLoadedEventCommand =>
            appLoadedEventCommand ?? (appLoadedEventCommand = new DelegateCommand(ExecuteAppLoadedEventCommand));

        private DelegateCommand<object> outputOrderCommand;
        public DelegateCommand<object> OutputOrderCommand =>
            outputOrderCommand ?? (outputOrderCommand = new DelegateCommand<object>(ExecuteOutputOrderCommand));
        private DelegateCommand appClosedEventCommand;
        public DelegateCommand AppClosedEventCommand =>
            appClosedEventCommand ?? (appClosedEventCommand = new DelegateCommand(ExecuteAppClosedEventCommand));
        #endregion
        #region 构造函数
        private readonly IDialogService dialogService;
        public MainWindowViewModel(IDialogService _dialogService)
        {
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
            dialogService = _dialogService;
        }
        #endregion
        #region 方法绑定函数
        void ExecuteAppLoadedEventCommand()
        {
            try
            {
                if (mysql.Connect())
                {
                    string str = "SELECT now()";
                    DataSet ds = mysql.Select(str);
                    DataTable dt = ds.Tables[0];
                    SQLState = dt.Rows[0][0].ToString().Contains(":");
                }
                mysql.DisConnect();
            }
            catch (Exception ex)
            {
                HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        void ExecuteAppClosedEventCommand()
        {
            try
            {
                mysql.DisConnect();
            }
            catch { }
        }
        void ExecuteMenuCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    DeliveryOrderPageVisibility = "Visible";
                    GoodsPageVisibility = "Collapsed";
                    InputOrderPageVisibility = "Collapsed";
                    OutputRecordPageVisibility = "Collapsed";
                    OutputOrderPageVisibility = "Collapsed";
                    break;
                case "1":
                    DeliveryOrderPageVisibility = "Visible";
                    GoodsPageVisibility = "Collapsed";
                    InputOrderPageVisibility = "Visible";
                    OutputRecordPageVisibility = "Collapsed";
                    OutputOrderPageVisibility = "Collapsed";
                    break;
                case "2":
                    DeliveryOrderPageVisibility = "Collapsed";
                    GoodsPageVisibility = "Collapsed";
                    InputOrderPageVisibility = "Collapsed";
                    OutputRecordPageVisibility = "Visible";
                    OutputOrderPageVisibility = "Collapsed";
                    break;
                case "3":
                    DeliveryOrderPageVisibility = "Collapsed";
                    GoodsPageVisibility = "Collapsed";
                    InputOrderPageVisibility = "Collapsed";
                    OutputRecordPageVisibility = "Collapsed";
                    OutputOrderPageVisibility = "Visible";
                    break;
                case "4":
                    DeliveryOrderPageVisibility = "Collapsed";
                    GoodsPageVisibility = "Visible";
                    InputOrderPageVisibility = "Collapsed";
                    OutputRecordPageVisibility = "Collapsed";
                    OutputOrderPageVisibility = "Collapsed";
                    break;
                case "10":
                    if (HandyControl.Controls.MessageBox.Show($"确认导出\"入库台账\"?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        using (ExcelPackage package = new ExcelPackage())
                        {
                            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sheet0");
                            worksheet.Cells[1, 1].Value = "序号";
                            worksheet.Cells[1, 2].Value = "物料编码";
                            worksheet.Cells[1, 3].Value = "物料名称";
                            worksheet.Cells[1, 4].Value = "物料型号";
                            worksheet.Cells[1, 5].Value = "数量";
                            worksheet.Cells[1, 6].Value = "研发出库单编号(仓库)";
                            worksheet.Cells[1, 7].Value = "研发入库单编号(研发自用)";
                            worksheet.Cells[1, 8].Value = "备注";
                            worksheet.Cells[1, 9].Value = "时间";
                            if (mysql.Connect())
                            {
                                string str = "SELECT * FROM m_inputorder ORDER BY created ASC";
                                DataSet ds = mysql.Select(str);
                                DataTable dt = ds.Tables[0];
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        worksheet.Cells[2 + i, 1].Value = i + 1;
                                        worksheet.Cells[2 + i, 2].Value = dt.Rows[i]["originalgcn"];
                                        worksheet.Cells[2 + i, 5].Value = dt.Rows[i]["count"];
                                        worksheet.Cells[2 + i, 7].Value = dt.Rows[i]["originaldcn"];
                                        worksheet.Cells[2 + i, 9].Value = Convert.ToDateTime(dt.Rows[i]["created"].ToString()).ToString();
                                        string str1 = $"SELECT * FROM m_dileveryorder WHERE cn = '{dt.Rows[i]["originaldcn"]}'";
                                        DataSet ds1 = mysql.Select(str1);
                                        DataTable dt1 = ds1.Tables[0];
                                        if (dt1.Rows.Count > 0)
                                        {
                                            worksheet.Cells[2 + i, 8].Value = dt1.Rows[0]["remark"].ToString();
                                        }
                                        string str2 = $"SELECT * FROM m_goods WHERE originalcn = '{dt.Rows[i]["originalgcn"]}'";
                                        DataSet ds2 = mysql.Select(str2);
                                        DataTable dt2 = ds2.Tables[0];
                                        if (dt2.Rows.Count > 0)
                                        {
                                            worksheet.Cells[2 + i, 3].Value = dt2.Rows[0]["name"].ToString();
                                            worksheet.Cells[2 + i, 4].Value = dt2.Rows[0]["model"].ToString();
                                        }
                                    }
                                }
                            }
                            mysql.DisConnect();
                            string filename = getSavePath();
                            if (filename != "")
                            {
                                package.SaveAs(new FileInfo(filename));
                            }
                        }                        
                    }
                    break;
                case "11":
                    if (HandyControl.Controls.MessageBox.Show($"确认导出\"出库台账\"?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        using (ExcelPackage package = new ExcelPackage())
                        {
                            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sheet0");
                            worksheet.Cells[1, 1].Value = "序号";
                            worksheet.Cells[1, 2].Value = "物料编码";
                            worksheet.Cells[1, 3].Value = "物料名称";
                            worksheet.Cells[1, 4].Value = "物料型号";
                            worksheet.Cells[1, 5].Value = "数量";
                            worksheet.Cells[1, 6].Value = "人员";
                            worksheet.Cells[1, 7].Value = "研发出库单编号(研发自用)";
                            worksheet.Cells[1, 8].Value = "备注";
                            worksheet.Cells[1, 9].Value = "时间";
                            if (mysql.Connect())
                            {
                                string str = "SELECT * FROM m_outputorder ORDER BY created ASC";
                                DataSet ds = mysql.Select(str);
                                DataTable dt = ds.Tables[0];
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        worksheet.Cells[2 + i, 1].Value = i + 1;
                                        worksheet.Cells[2 + i, 2].Value = dt.Rows[i]["originalgcn"];
                                        worksheet.Cells[2 + i, 5].Value = dt.Rows[i]["count"];
                                        worksheet.Cells[2 + i, 7].Value = dt.Rows[i]["recordcn"];
                                        worksheet.Cells[2 + i, 9].Value = Convert.ToDateTime(dt.Rows[i]["created"].ToString()).ToString();
                                        string str1 = $"SELECT * FROM m_outputorderrecord WHERE cn = '{dt.Rows[i]["recordcn"]}'";
                                        DataSet ds1 = mysql.Select(str1);
                                        DataTable dt1 = ds1.Tables[0];
                                        if (dt1.Rows.Count > 0)
                                        {
                                            worksheet.Cells[2 + i, 7].Value = dt1.Rows[0]["ename"].ToString();
                                            worksheet.Cells[2 + i, 8].Value = dt1.Rows[0]["remark"].ToString();
                                        }
                                        string str2 = $"SELECT * FROM m_goods WHERE originalcn = '{dt.Rows[i]["originalgcn"]}'";
                                        DataSet ds2 = mysql.Select(str2);
                                        DataTable dt2 = ds2.Tables[0];
                                        if (dt2.Rows.Count > 0)
                                        {
                                            worksheet.Cells[2 + i, 3].Value = dt2.Rows[0]["name"].ToString();
                                            worksheet.Cells[2 + i, 4].Value = dt2.Rows[0]["model"].ToString();
                                        }
                                    }
                                }
                            }
                            mysql.DisConnect();
                            string filename = getSavePath();
                            if (filename != "")
                            {
                                package.SaveAs(new FileInfo(filename));
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        async void ExecuteDileveryOrderCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        try
                        {
                            CheckDileveryOrder();
                        }
                        catch (Exception ex)
                        {
                            HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                  
                    }
                    break;
                case "1":
                    {

                        OpenFileDialog openFileDialog = new OpenFileDialog();
                        openFileDialog.InitialDirectory = @"C:\Users\admin\Desktop";
                        openFileDialog.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
                        if (openFileDialog.ShowDialog() == true)
                        {
                            try
                            {
                                
                                string fullfileName = openFileDialog.FileName;
                                string fileName = openFileDialog.SafeFileName;
                                string[] strs = fileName.Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                                FileInfo existingFile = new FileInfo(fullfileName);
                                using (ExcelPackage package = new ExcelPackage(existingFile))
                                {
                                    ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
                                    if (worksheet.Dimension.End.Column == 4)
                                    {
                                        if (mysql.Connect())
                                        {

                                            string str = $"SELECT * FROM m_dileveryorder WHERE cn = '{strs[0]}'";
                                            DataSet ds = mysql.Select(str);
                                            DataTable dt = ds.Tables[0];
                                            if (dt.Rows.Count > 0)
                                            {
                                                if (HandyControl.Controls.MessageBox.Show($"研发出库单{strs[0]}已存在，是否继续导入?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                                {
                                                    actionFinsh = false;
                                                    AddDelivery(worksheet, strs[0]);
                                                }
                                            }
                                            else
                                            {
                                                actionFinsh = false;
                                                AddDelivery(worksheet, strs[0]);
                                            }
                                            await Task.Run(()=> {
                                                while (!actionFinsh)
                                                {
                                                    System.Threading.Thread.Sleep(100);
                                                }
                                            });
                                        }
                                        else
                                        {
                                            mysql.DisConnect();
                                        }
                                    }
                                    else
                                    {
                                        HandyControl.Controls.MessageBox.Show("Excel格式不合格", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                }

                            }
                            catch (Exception ex)
                            {
                                HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        void ExecuteGoodsCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        try
                        {
                            CheckGoods();
                        }
                        catch (Exception ex)
                        {
                            HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                case "1":
                    {
                        DialogParameters param = new DialogParameters();
                        if (GoodsCheckSelectedItem != null)
                        {
                            param.Add("Code", GoodsCheckSelectedItem.Code);
                            param.Add("Name", GoodsCheckSelectedItem.Name);
                            param.Add("Model", GoodsCheckSelectedItem.Model);
                            param.Add("Unit", GoodsCheckSelectedItem.Unit);
                        }
                        else
                        {
                            param.Add("Code", "");
                            param.Add("Name", "");
                            param.Add("Model", "");
                            param.Add("Unit", "");
                        }
                        dialogService.ShowDialog("AddGoodsDialog", param, arg => {
                            if (arg.Result == ButtonResult.Yes)
                            {
                                

                                string code = arg.Parameters.GetValue<string>("Code");
                                string name = arg.Parameters.GetValue<string>("Name");
                                string model = arg.Parameters.GetValue<string>("Model");
                                int count = arg.Parameters.GetValue<int>("Count");
                                string unit = arg.Parameters.GetValue<string>("Unit");
                                string pos1 = arg.Parameters.GetValue<string>("Pos1");
                                string pos2 = arg.Parameters.GetValue<string>("Pos2");
                                string pos3 = arg.Parameters.GetValue<string>("Pos3");
                                if (code == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("原仓库编码为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                if (name == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("名称为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                if (model == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("型号为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                if (unit == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("单位为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                if (pos1 == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("货架编码1为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                if (pos2 == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("货架编码2为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                if (pos3 == "")
                                {
                                    HandyControl.Controls.MessageBox.Show("货架编码3为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    return;
                                }
                                string position = pos1 + pos2 + pos3;
                                if (mysql.Connect())
                                {
                                    string str = $"SELECT * FROM m_goods WHERE originalcn = '{code}'";
                                    DataSet ds = mysql.Select(str);
                                    DataTable dt = ds.Tables[0];
                                    if (dt.Rows.Count > 0)//已存在，更新
                                    {
                                        str = $"UPDATE m_goods SET name = '{name}',model = '{model}',count = count + {count},position = '{position}',unit = '{unit}'  WHERE originalcn = '{code}'";
                                        mysql.executeQuery(str);
                                    }
                                    else //不存在，插入
                                    {
                                        str = $"INSERT INTO m_goods (originalcn,name,model,count,position,unit) VALUES ('{code}','{name}','{model}',{count},'{position}','{unit}')";
                                        mysql.executeQuery(str);
                                    }

                                }
                                mysql.DisConnect();

                                GoodsOriginalCN = code;
                                CheckGoods();
                            }

                        });
                    }
                    break;
                case "2":
                    {
                        if (GoodsCheck.Count > 0)
                        {
                            try
                            {
                                using (ExcelPackage package = new ExcelPackage())
                                {
                                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sheet0");
                                    worksheet.Cells["A1"].Value = "序号";
                                    worksheet.Cells["B1"].Value = "原仓库编码";
                                    worksheet.Cells["C1"].Value = "名称";
                                    worksheet.Cells["D1"].Value = "型号";
                                    worksheet.Cells["E1"].Value = "数量";
                                    worksheet.Cells["F1"].Value = "单位";
                                    worksheet.Cells["A1:F1"].Style.Font.Bold = true;
                                    for (int i = 0; i < GoodsCheck.Count; i++)
                                    {
                                        worksheet.Cells["A" + (i + 2).ToString()].Value = i + 1;
                                        worksheet.Cells["B" + (i + 2).ToString()].Value = GoodsCheck[i].Code;
                                        worksheet.Cells["C" + (i + 2).ToString()].Value = GoodsCheck[i].Name;
                                        worksheet.Cells["D" + (i + 2).ToString()].Value = GoodsCheck[i].Model;
                                        worksheet.Cells["E" + (i + 2).ToString()].Value = GoodsCheck[i].Count;
                                        worksheet.Cells["F" + (i + 2).ToString()].Value = GoodsCheck[i].Unit;
                                    }
                                    string filename = getSavePath();
                                    if (filename != "")
                                    {
                                        package.SaveAs(new FileInfo(filename));
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                        else
                        {
                            HandyControl.Controls.MessageBox.Show("无导出项", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        void ExecuteInputOrderCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        try
                        {
                            CheckInputOrder();
                        }
                        catch (Exception ex)
                        {
                            HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                //case "1":
                //    {
                        
                //    }
                //    break;
                default:
                    break;
            }
        }
        async void ExecuteOutputOrderRecordCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        try
                        {
                            CheckOutputRecord();
                        }
                        catch (Exception ex)
                        {
                            HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                case "1":
                    {
                        bool successflag = false;
                        OpenFileDialog openFileDialog = new OpenFileDialog();
                        openFileDialog.InitialDirectory = @"C:\Users\admin\Desktop";
                        openFileDialog.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";
                        if (openFileDialog.ShowDialog() == true)
                        {
                            try
                            {
                                string fullfileName = openFileDialog.FileName;
                                FileInfo existingFile = new FileInfo(fullfileName);
                                using (ExcelPackage package = new ExcelPackage(existingFile))
                                {
                                    ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
                                    if (worksheet.Dimension.End.Column == 4)
                                    {
                                        string code = "";
                                        
                                        if (mysql.Connect())
                                        {
                                            actionFinsh = false;
                                            string str = "SELECT COUNT(*) FROM m_outputorderrecord";
                                            DataSet ds = mysql.Select(str);
                                            DataTable dt = ds.Tables[0];
                                            code = (int.Parse(dt.Rows[0][0].ToString()) + 1).ToString("D6");
                                            DialogParameters param = new DialogParameters();
                                            param.Add("Title", "添加出料单");
                                            param.Add("Code", code);
                                            dialogService.ShowDialog("AddOutputRecordDialog", param,async arg => {
                                                if (arg.Result == ButtonResult.Yes)
                                                {
                                                    string person = arg.Parameters.GetValue<string>("Person");
                                                    string remark = arg.Parameters.GetValue<string>("Remark");
                                                    DateTime created1 = arg.Parameters.GetValue<DateTime>("Created");
                                                    if (person != "")
                                                    {
                                                        await Task.Run(()=> {
                                                            string str0 = $"INSERT INTO m_outputorderrecord (cn,remark,ename,created) VALUES ('{code}','{remark}','{person}','{created1.ToString("yyyy-MM-dd HH:mm:ss")}')";
                                                            mysql.executeQuery(str0);

                                                            for (int i = 1; i <= worksheet.Dimension.End.Row; i++)
                                                            {

                                                                //库存处理
                                                                string str1 = $"SELECT * FROM m_goods WHERE originalcn = '{worksheet.Cells["A" + i.ToString()].Value}'";
                                                                DataSet ds1 = mysql.Select(str1);
                                                                DataTable dt1 = ds1.Tables[0];
                                                                if (dt1.Rows.Count > 0)//存在
                                                                {
                                                                    if (int.Parse(worksheet.Cells["D" + i.ToString()].Value.ToString()) > 0)//有库存
                                                                    {
                                                                        int remaincount = int.Parse(dt1.Rows[0]["count"].ToString()) - int.Parse(worksheet.Cells["D" + i.ToString()].Value.ToString());
                                                                        int actualoutputcout;
                                                                        if (remaincount >= 0)//库存满足出货
                                                                        {
                                                                            actualoutputcout = int.Parse(worksheet.Cells["D" + i.ToString()].Value.ToString());
                                                                            worksheet.Cells["E" + i.ToString()].Value = "OK";
                                                                            worksheet.Cells["E" + i.ToString()].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                                            worksheet.Cells["E" + i.ToString()].Style.Fill.BackgroundColor.SetColor(Color.Lime);
                                                                        }
                                                                        else//库存数量不够出货
                                                                        {
                                                                            actualoutputcout = int.Parse(dt1.Rows[0]["count"].ToString());
                                                                            worksheet.Cells["E" + i.ToString()].Value = $"缺货；实际出货数量为{actualoutputcout}";
                                                                            worksheet.Cells["E" + i.ToString()].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                                            worksheet.Cells["E" + i.ToString()].Style.Fill.BackgroundColor.SetColor(Color.Yellow);
                                                                        }
                                                                        string str2 = $"UPDATE m_goods SET count = count - {actualoutputcout}  WHERE originalcn = '{worksheet.Cells["A" + i.ToString()].Value}'";
                                                                        mysql.executeQuery(str2);

                                                                        //插入记录
                                                                        string str3 = $"INSERT INTO m_outputorder (recordcn,originalgcn,count,created) VALUES ('{code}','{worksheet.Cells["A" + i.ToString()].Value}',{actualoutputcout},'{created1.ToString("yyyy-MM-dd HH:mm:ss")}')";
                                                                        mysql.executeQuery(str3);
                                                                    }
                                                                    else//没有库存
                                                                    {
                                                                        //不出货
                                                                        worksheet.Cells["E" + i.ToString()].Value = "缺货";
                                                                        worksheet.Cells["E" + i.ToString()].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                                        worksheet.Cells["E" + i.ToString()].Style.Fill.BackgroundColor.SetColor(Color.Red);
                                                                    }


                                                                }
                                                                else //不存在
                                                                {
                                                                    //不出货
                                                                    worksheet.Cells["E" + i.ToString()].Value = "无库存记录";
                                                                    worksheet.Cells["E" + i.ToString()].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                                                    worksheet.Cells["E" + i.ToString()].Style.Fill.BackgroundColor.SetColor(Color.Red);
                                                                }
                                                            }
                                                            successflag = true;
                                                        });
                                                        HandyControl.Controls.MessageBox.Show($"{code}出库完成", "信息", MessageBoxButton.OK, MessageBoxImage.Information);
                                                    }
                                                    else
                                                    {
                                                        HandyControl.Controls.MessageBox.Show("人员名字不能为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                                    }
                                                }
                                                mysql.DisConnect();
                                                actionFinsh = true;
                                            });
                                            await Task.Run(()=> {
                                                while (!actionFinsh)
                                                {
                                                    System.Threading.Thread.Sleep(100);
                                                }
                                            });
                                        }
                                        else
                                        {
                                            mysql.DisConnect();
                                        }

                                        if (successflag)
                                        {
                                            string filename = getSavePath();
                                            if (filename != "")
                                            {
                                                package.SaveAs(new FileInfo(filename));
                                            }
                                            OutputOrderRecordCN = code;
                                            CheckOutputRecord();
                                        }
                                        
                                    }
                                    else
                                    {
                                        HandyControl.Controls.MessageBox.Show("Excel格式不合格", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                }
                                  
                            }
                            catch (Exception ex)
                            {
                                HandyControl.Controls.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                    break;
                case "2":
                    {
                        if (OutputOrderRecordSelectedItem != null)
                        {
                            DialogParameters param = new DialogParameters();
                            param.Add("Title", "编辑出料单");
                            param.Add("Code", OutputOrderRecordSelectedItem.Code);
                            param.Add("Person", OutputOrderRecordSelectedItem.Person);
                            param.Add("Remark", OutputOrderRecordSelectedItem.Remark);
                            param.Add("Created", OutputOrderRecordSelectedItem.Created);
                            dialogService.ShowDialog("AddOutputRecordDialog", param,arg => {
                                if (arg.Result == ButtonResult.Yes)
                                {
                                    string person = arg.Parameters.GetValue<string>("Person");
                                    string remark = arg.Parameters.GetValue<string>("Remark");
                                    DateTime created1 = arg.Parameters.GetValue<DateTime>("Created");
                                    if (person != "")
                                    {
                                        if (mysql.Connect())
                                        {
                                            string str0 = $"UPDATE m_outputorderrecord SET ename = '{person}',remark = '{remark}',created = '{created1.ToString("yyyy-MM-dd HH:mm:ss")}' WHERE cn = '{OutputOrderRecordSelectedItem.Code}'";
                                            mysql.executeQuery(str0);
                                        }
                                        mysql.DisConnect();
                                        OutputOrderRecordCN = OutputOrderRecordSelectedItem.Code;
                                        CheckOutputRecord();
                                    }
                                    else
                                    {
                                        HandyControl.Controls.MessageBox.Show("人员名字不能为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                }
                            });
                        }
                        else
                        {
                            HandyControl.Controls.MessageBox.Show("未选择任何出料单", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        void ExecuteOutputOrderCommand(object obj)
        {
            switch (obj.ToString())
            {
                case "0":
                    {
                        CheckOutputOrder();
                    }
                    break;
                default:
                    break;
            }
        }
        #endregion
        #region 自定义函数
        private void CheckDileveryOrder()
        {
            DileveryOrderCheck.Clear();
            if (mysql.Connect())
            {
                string str;
                if (DileveryorderCN != "")
                {
                    str = $"SELECT * FROM m_dileveryorder WHERE cn = '{DileveryorderCN}'";
                }
                else if (DileveryorderRemark != "")
                {
                    str = $"SELECT * FROM m_dileveryorder WHERE remark LIKE '%{DileveryorderRemark}%'";
                }
                else
                {
                    str = $"SELECT * FROM m_dileveryorder WHERE created >= '{DileveryOrderCheckStartDate.ToString("yyyy-MM-dd")}' AND created <= '{DileveryrderCheckEndDate.AddDays(1).ToString("yyyy-MM-dd")}'";
                }

                DataSet ds = mysql.Select(str);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DileveryOrderCheck.Add(
                            new Dileveryorder()
                            {
                                //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                Index = i + 1,
                                Code = dt.Rows[i]["cn"].ToString(),
                                Remark = dt.Rows[i]["remark"].ToString(),
                                Created = Convert.ToDateTime(dt.Rows[i]["created"].ToString())
                            }
                            );
                    }
                }
            }
            mysql.DisConnect();
        }
        private void CheckGoods()
        {
            GoodsCheck.Clear();
            if (mysql.Connect())
            {
                string str = "";
                if (GoodsOriginalCN != "")
                {
                    str = $"SELECT * FROM m_goods WHERE originalcn = '{GoodsOriginalCN}'";
                }
                else if (GoodsName != "")
                {
                    str = $"SELECT * FROM m_goods WHERE name LIKE '%{GoodsName}%'";
                }
                else if (GoodsModel != "")
                {
                    str = $"SELECT * FROM m_goods WHERE model LIKE '%{GoodsModel}%'";
                }
                else if (GoodsPosition != "")
                {
                    str = $"SELECT * FROM m_goods WHERE position LIKE '%{GoodsPosition}%'";
                }
                else
                {
                    str = "SELECT * FROM m_goods";
                }
                if (IsGoodsCountGreaterthanZero)
                {
                    if (str.Contains("WHERE"))
                    {
                        str += $" AND count > 0";
                    }
                    else
                    {
                        str += $" WHERE count > 0";
                    }
                }
                DataSet ds = mysql.Select(str);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        GoodsCheck.Add(
                            new Goods()
                            {
                                //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                Index = i + 1,
                                Code = dt.Rows[i]["originalcn"].ToString(),
                                Name = dt.Rows[i]["name"].ToString(),
                                Count = int.Parse(dt.Rows[i]["count"].ToString()),
                                Model = dt.Rows[i]["model"].ToString(),
                                Position = dt.Rows[i]["position"].ToString(),
                                Unit = dt.Rows[i]["unit"].ToString()
                            }
                            );
                    }
                }
            }
            mysql.DisConnect();
        }
        private void CheckInputOrder()
        {
            InputOrderCheck.Clear();
            if (mysql.Connect())
            {
                string str = "";
                if (InputOrderOriginalDCN != "")
                {
                    str = $"SELECT * FROM m_inputorder WHERE originaldcn = '{InputOrderOriginalDCN}'";
                    DataSet ds = mysql.Select(str);
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string str1 = $"SELECT * FROM m_goods WHERE originalcn = '{dt.Rows[i]["originalgcn"]}'";
                            DataSet ds1 = mysql.Select(str1);
                            DataTable dt1 = ds1.Tables[0];
                            InputGoods newItem;
                            if (dt1.Rows.Count > 0)
                            {
                                newItem = new InputGoods()
                                {
                                    //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                    Index1 = i + 1,
                                    Created = Convert.ToDateTime(dt.Rows[i]["created"].ToString()),
                                    InputOrderCode = dt.Rows[i]["originaldcn"].ToString(),
                                    Code = dt.Rows[i]["originalgcn"].ToString(),
                                    Name = dt1.Rows[0]["name"].ToString(),
                                    Count = int.Parse(dt.Rows[i]["count"].ToString()),
                                    Model = dt1.Rows[0]["model"].ToString(),
                                    Position = dt1.Rows[0]["position"].ToString(),
                                    Unit = dt1.Rows[0]["unit"].ToString()

                                };
                            }
                            else
                            {
                                newItem = new InputGoods()
                                {
                                    //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                    Index1 = i + 1,
                                    Created = Convert.ToDateTime(dt.Rows[i]["created"].ToString()),
                                    InputOrderCode = dt.Rows[i]["originaldcn"].ToString(),
                                    Code = dt.Rows[i]["originalgcn"].ToString(),
                                    Name = "Unkown",
                                    Count = int.Parse(dt.Rows[i]["count"].ToString()),
                                    Model = "Unkown",
                                    Position = "Unkown",
                                    Unit = "Unkown"

                                };
                            }
                            InputOrderCheck.Add(newItem);
                        }
                    }
                }
                else
                {
                    HandyControl.Controls.MessageBox.Show("研发出库单号不能为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                
            }
            mysql.DisConnect();
        }
        private void AddDelivery(ExcelWorksheet worksheet,string originaldcn)
        {
            
            DialogParameters param = new DialogParameters();
            param.Add("Code", originaldcn);
            dialogService.ShowDialog("AddDileveryOrderDialog", param,async arg => {
                if (arg.Result == ButtonResult.Yes)
                {
                    string remark = arg.Parameters.GetValue<string>("Remark");
                    DateTime created1 = arg.Parameters.GetValue<DateTime>("Created");
                    await Task.Run(() => {

                        string str0 = $"INSERT INTO m_dileveryorder (cn,remark,created) VALUES ('{originaldcn}','{remark}','{created1.ToString("yyyy-MM-dd HH:mm:ss")}')";
                        mysql.executeQuery(str0);
                        for (int i = 1; i <= worksheet.Dimension.End.Row; i++)
                        {
                            //插入记录
                            string str = $"INSERT INTO m_inputorder (originaldcn,originalgcn,count,created) VALUES ('{originaldcn}','{worksheet.Cells["A" + i.ToString()].Value}',{worksheet.Cells["D" + i.ToString()].Value},'{created1.ToString("yyyy-MM-dd HH:mm:ss")}')";
                            mysql.executeQuery(str);

                            //库存处理
                            string str1 = $"SELECT * FROM m_goods WHERE originalcn = '{worksheet.Cells["A" + i.ToString()].Value}'";
                            DataSet ds1 = mysql.Select(str1);
                            DataTable dt1 = ds1.Tables[0];
                            if (dt1.Rows.Count > 0)//存在，更新
                            {
                                string str2 = $"UPDATE m_goods SET count = count + {worksheet.Cells["D" + i.ToString()].Value}  WHERE originalcn = '{worksheet.Cells["A" + i.ToString()].Value}'";
                                mysql.executeQuery(str2);
                            }
                            else //不存在，创建
                            {
                                string name, model;
                                string[] strs1 = worksheet.Cells["B" + i.ToString()].Value.ToString().Split(new String[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                                if (strs1.Length > 1)
                                {
                                    name = strs1[0];
                                    model = strs1[1];
                                }
                                else
                                {
                                    name = strs1[0];
                                    model = "";
                                }
                                string str2 = $"INSERT INTO m_goods (originalcn,name,model,count,unit) VALUES ('{worksheet.Cells["A" + i.ToString()].Value}','{name}','{model}',{worksheet.Cells["D" + i.ToString()].Value},'{worksheet.Cells["C" + i.ToString()].Value}')";
                                mysql.executeQuery(str2);
                            }
                        }
                    });
                    HandyControl.Controls.MessageBox.Show($"{originaldcn}上传完成", "信息", MessageBoxButton.OK, MessageBoxImage.Information);
                    mysql.DisConnect();
                    DileveryorderCN = originaldcn;
                    CheckDileveryOrder();
                }
                else
                {
                    mysql.DisConnect();
                }
                actionFinsh = true;
            });


            
        }
        private void CheckOutputRecord()
        {
            OutputOrderRecordCheck.Clear();
            if (mysql.Connect())
            {
                string str;
                if (OutputOrderRecordCN != "")
                {
                    str = $"SELECT * FROM m_outputorderrecord WHERE cn = '{OutputOrderRecordCN}'";
                }
                else if (OutputOrderRecordPerson != "")
                {
                    str = $"SELECT * FROM m_outputorderrecord WHERE ename = '{OutputOrderRecordPerson}'";
                }
                else if (OutputOrderRecordRemark != "")
                {
                    str = $"SELECT * FROM m_outputorderrecord WHERE remark LIKE '%{OutputOrderRecordRemark}%'";
                }
                else
                {
                    str = $"SELECT * FROM m_outputorderrecord WHERE created >= '{OutputOrderRecordCheckStartDate.ToString("yyyy-MM-dd")}' AND created <= '{OutputOrderRecordCheckEndDate.AddDays(1).ToString("yyyy-MM-dd")}'";
                }

                DataSet ds = mysql.Select(str);
                DataTable dt = ds.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        OutputOrderRecordCheck.Add(
                            new OutputRecord()
                            {
                                //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                Index = i + 1,
                                Code = dt.Rows[i]["cn"].ToString(),
                                Person = dt.Rows[i]["ename"].ToString(),
                                Remark = dt.Rows[i]["remark"].ToString(),
                                Created = Convert.ToDateTime(dt.Rows[i]["created"].ToString())
                            }
                            );
                    }
                }
            }
            mysql.DisConnect();
        }
        private void CheckOutputOrder()
        {
            OutputOrderCheck.Clear();
            if (mysql.Connect())
            {
                string str = "";
                if (OutputOrderCN != "")
                {
                    str = $"SELECT * FROM m_outputorder WHERE recordcn = '{OutputOrderCN}'";
                    DataSet ds = mysql.Select(str);
                    DataTable dt = ds.Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string str1 = $"SELECT * FROM m_goods WHERE originalcn = '{dt.Rows[i]["originalgcn"]}'";
                            DataSet ds1 = mysql.Select(str1);
                            DataTable dt1 = ds1.Tables[0];
                            OutputGoods newItem;
                            if (dt1.Rows.Count > 0)
                            {
                                newItem = new OutputGoods()
                                {
                                    //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                    Index1 = i + 1,
                                    Created = Convert.ToDateTime(dt.Rows[i]["created"].ToString()),
                                    OutputOrderCode = dt.Rows[i]["recordcn"].ToString(),
                                    Code = dt.Rows[i]["originalgcn"].ToString(),
                                    Name = dt1.Rows[0]["name"].ToString(),
                                    Count = int.Parse(dt.Rows[i]["count"].ToString()),
                                    Model = dt1.Rows[0]["model"].ToString(),
                                    Position = dt1.Rows[0]["position"].ToString(),
                                    Unit = dt1.Rows[0]["unit"].ToString()
                                };

                            }
                            else
                            {
                                newItem = new OutputGoods()
                                {
                                    //Id = int.Parse(dt.Rows[i]["id"].ToString()),
                                    Index1 = i + 1,
                                    Created = Convert.ToDateTime(dt.Rows[i]["created"].ToString()),
                                    OutputOrderCode = dt.Rows[i]["recordcn"].ToString(),
                                    Code = dt.Rows[i]["originalgcn"].ToString(),
                                    Name = "Unkown",
                                    Count = int.Parse(dt.Rows[i]["count"].ToString()),
                                    Model = "Unkown",
                                    Position = "Unkown",
                                    Unit = "Unkown"

                                };
                            }
                            string str2 = $"SELECT * FROM m_outputorderrecord WHERE cn = '{dt.Rows[i]["recordcn"]}'";
                            DataSet ds2 = mysql.Select(str2);
                            DataTable dt2 = ds2.Tables[0];
                            if (dt2.Rows.Count > 0)
                            {
                                newItem.Person = dt2.Rows[0]["ename"].ToString();
                            }
                            else
                            {
                                newItem.Person = "Unkown";
                            }
                            OutputOrderCheck.Add(newItem);
                        }
                    }
                }
                else
                {
                    HandyControl.Controls.MessageBox.Show("出库单号不能为空", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

            }
            mysql.DisConnect();
        }
        private string getSavePath()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Excel Files|*.xlsx;*.xls;*.xlsm";
            if (saveFileDialog.ShowDialog() == true)
                return saveFileDialog.FileName;
            else
            {
                return "";
            }
        }
        #endregion
    }
}
